class code5 {
    public boolean checkInclusion(String s1, String s2) {
        char[] ss1 = s1.toCharArray();
        char[] ss2 = s2.toCharArray();

        int[] hash1 = new int[26];
        int[] hash2 = new int[26];
        for(char ch:ss1) {
            hash1[ch-'a']++;
        }
        int len = s1.length();
        int left=0,right = 0;
        int count = 0;//有效字符的个数
        while(right < s2.length()) {
            //进
            hash2[ss2[right]-'a']++;
            if(hash2[ss2[right]-'a'] <= hash1[ss2[right]-'a']) {
                count++;
            }
            //判断
            if(right-left+1 > len) {
                //出
                if(hash2[ss2[left]-'a'] <= hash1[ss2[left]-'a']) {
                    count--;
                }
                hash2[ss2[left++]-'a']--;
            }
            if(count == len) {
                return true;
            }
            right++;
        }
        return false;
    }
}